# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=tinygltf
pkgver=2.9.2
pkgrel=0
_pkgsover=6d
pkgdesc="Header only C++11 tiny glTF 2.0 library"
url="https://github.com/syoyo/tinygltf"
arch="all"
license="MIT"
depends_dev="nlohmann-json stb"
makedepends="cmake samurai $depends_dev"
checkdepends="catch2"
subpackages="$pkgname-dev"
source="tinygltf-$pkgver.tar.gz::https://github.com/syoyo/tinygltf/archive/refs/tags/v$pkgver.tar.gz
	0001-Fix-build-system.patch
	0002-Fix-third-party-includes.patch
	0003-Integrate-unit-tests-into-CMake-build.patch
	0004-Add-pkgconfig-file.patch
	0006-Big-endian-fix.patch"

prepare() {
	default_prepare
	rm json.hpp tests/catch.hpp
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_TESTING="$(want_check && echo TRUE || echo FALSE)" \
		-DTINYGLTF_VERSION=$pkgver \
		-DTINYGLTF_SOVERSION=$_pkgsover \
		-DTINYGLTF_BUILD_LOADER_EXAMPLE=OFF \
		-DTINYGLTF_BUILD_GL_EXAMPLES=OFF \
		-DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=OFF \
		$crossopts
	cmake --build build
}

check() {
	mv $builddir/build/tests/tester $builddir/tests
	cd tests
	./tester
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
daee181b4212c7ba96b3e791fc28aa77102555323a2fef167edaee24d6e13ba4c9a844d028a3f2734760a65440face0eb759d034daecd4c0e3b4c4b67dadfd72  tinygltf-2.9.2.tar.gz
09a57ed2111b00ee12c02faf0afa14c700d7ca7e87f8c0f0a996e8fedfa17d5aa1add6674512f1afd2147a96f67193e978a9c32e34aa57f0ec5aa19e77013e6f  0001-Fix-build-system.patch
4270d48373940d5483735e142470c457ff344be8d254cdcd09f7eb131ad9ec99ff336ec0f948c6b70cedcc8d0ff27b0031823d717ba054ca4b7dbbc46581f0fd  0002-Fix-third-party-includes.patch
88b137986fed378ee552234eb53d83dbc791f9cc554024301b37680311fd1d4110ff32ae7c3490e0a8ce2887e72af32e0d995137d43e89f4c241c402d28520d1  0003-Integrate-unit-tests-into-CMake-build.patch
764f3a1fc3a0ac86c86ff7b8b5634fa2cd55fde7ce3979aeccf4431690515bf27251678edbd03891d487beac2f4851d2e98891ac20a69759f9772056352eaca2  0004-Add-pkgconfig-file.patch
aa1568c2c31d3c48aca9d0b1c585a2b19940250dcf5f14a4d86ef8952b18b9d9390dd1ca0dc2859464802083f23a8fc5d4f620e13324a61bad2dd270e1fb7a8b  0006-Big-endian-fix.patch
"
